package org.zn.etl.job.handler.extend;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.stereotype.Component;
import org.zn.datax.common.entity.ColumnInfo;
import org.zn.etl.job.transformer.DataTransformer;

import lombok.extern.slf4j.Slf4j;

@Component("orguserInfoTrans")
@Slf4j
public class OrguserInfoTrans extends CitiyTrans{

	private static final String GKFYH="010103";
	private static final String ZGJCKYH="010133";
	private static final String ZGNYFZYH="0101317";
	
	@Override
	public List<Map<String, Object>> transform(List<Map<String, Object>> data,
			List<Pair<ColumnInfo, ColumnInfo>> columnMappingPairs) {
		// TODO Auto-generated method stub
		
		String key= getUseKey(data.get(0));
		
		for (Map<String, Object> it : data) {
		
			try {
				
			String organname=(String) it.get("organname");
			String usertype=(String) it.get("usertype");
			
			if(StringUtils.isNotEmpty(organname)&& StringUtils.isNotEmpty(usertype)) {
				
				//国家开发银行
				if(GKFYH.equals(usertype)) {
					it.put("usertype","0113");
				}
				
				//进出口银行
				else if(ZGJCKYH.equals(usertype)) {
					it.put("usertype","011401");
				}
				//农业发展
				else if(ZGNYFZYH.equals(usertype)) {
					it.put("usertype","011402");
				}
				//消费金融
				else if(usertype.startsWith("01")){
					
					if(organname.contains("金融资产") ) {
						it.put("usertype","0115");
					}
					else if(organname.contains("汽车金融") ) {
						it.put("usertype","0116");
					}
					else if(organname.contains("消费金融") ) {
						it.put("usertype","0117");
					}
		
				}
				//小额贷款
				else if(usertype.startsWith("02")){
					
					if(organname.contains("小额贷款") ) {
						it.put("usertype","0206");
					}
					
				}
				
			}
			
			if(key==null) {
				log.info("OrguserInfoTrans: No citiy UseKey");
				return data;
			}
			
			transCity(it, key);
			
			} catch (Exception e) {
				log.error("OrguserInfoTrans error, Citiy UseKey:{}  ,data:{}",key,it,e);
				
			}
			
		
		}
		
		
		return null;
	}

}
